package com.jxnu.escms.Service.BinService.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jxnu.escms.Dao.BinDao.BinDao;
import com.jxnu.escms.Pojo.PageResult;
import com.jxnu.escms.Pojo.User;
import com.jxnu.escms.Service.BinService.BinService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Service
public class BinServiceImpl implements BinService {
    @Resource
    private BinDao binDao;

    @Override
    public PageResult<User> getDeletedUsers(int start, int pageSize) {

        Page<Object> page = PageHelper.startPage(start, pageSize);

        Page<User> deletedUsers = (Page<User>) binDao.getDeletedUsers();

        return new PageResult<User>(Math.toIntExact(deletedUsers.getTotal()), deletedUsers);
    }

    @Override
    public int killUser(int id) {
        return binDao.killUser(id);
    }

    @Override
    public int restartUser(int adminId, int userId, String type) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newTime = df.format(new Date());
        return binDao.restoreUser(adminId, userId, type, newTime);
    }

    @Override
    public List<User> getAllDeletedUsers() {
        return binDao.getDeletedUsers();
    }
}
